//
//  TrackEventsViewController.m
//  Best
//
//  Created by iDeneb on 5/15/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "TrackEventsViewController.h"
#import "EditSettingsViewController.h"
#import "EditSettingCell.h"
#import "EventsCellViewController.h"

@implementation TrackEventsViewController

#define ROW_HEIGHT 60
@synthesize myscrollView;


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
	return 3;
}

- (IBAction)done:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
    //if ([delegate respondsToSelector:@selector(setupViewController:didFinishSetupWithInfo:)]) {
    //    [delegate setupViewController:self didFinishSetupWithInfo:setupInfo];
    //}
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *today_test = NSLocalizedString(@"event_track", @"");
	today_test = [today_test stringByAppendingString:@"            "];
	today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_time", @"")];
	//today_test = [today_test stringByAppendingString:@"       "];
	//today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_detail", @"")];
	
	return today_test;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *CellIdentifier = @"Cell";

	EventsCellViewController *cell = (EventsCellViewController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

	if (cell == nil) {
		//cell = [self tableViewCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
		EventsCellViewController *controller = [[EventsCellViewController alloc] initWithNibName:@"TrackEventCell" bundle:nil];
		[controller setUserCount:indexPath.row];
		//cell = [[[EventsCellViewController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
		cell = (UITableViewCell *)controller.view;
	}

	return cell;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    EditSettingCell *cell = (EditSettingCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[EditSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	switch (indexPath.row) {
		case 0:{
			NSString *today_test = NSLocalizedString(@"7/24/2010 2:06:27 PM", @"");
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_transfer", @"")];
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_detail1", @"")];
			
			[cell setText:today_test];
		}
			//[cell setTextFieldToEdit:self.serverTextField];
			//[[cell contentView] addSubview:self.serverTextField];
			//[cell setTextFieldToEdit:self.serverTextField];
			break;
		case 1:{
			NSString *today_test = NSLocalizedString(@"7/24/2010 6:06:27 PM", @"");
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_update", @"")];
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_detail2", @"")];
			
			[cell setText:today_test];
		}
			//[cell setText:NSLocalizedString(@"SO-002 (hangzhou/qingdao/transfer)", @"")];
			break;
		case 2:{
			NSString *today_test = NSLocalizedString(@"7/24/2010 4:06:27 PM", @"");
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"event_finish", @"")];
			today_test = [today_test stringByAppendingString:@"  "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"", @"")];
			
			[cell setText:today_test];
		}
			//[cell setText:NSLocalizedString(@"SO-003 (qingdao/jinan/failed)", @"")];
			break;
			
		default:
			break;
	}
    // Configure the cell...
    
    return cell;
}
*/


// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}



#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
	//OrderDetailViewController *detailViewController = nil;
	/*switch (indexPath.row) {
		case 0:
			return;
		case 1:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			break;
		case 2:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			
			break;
		case 3:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			break;
			
		default:
			break;
	 */
	//}
	//[self.navigationController pushViewController:detailViewController animated:YES];
	//[detailViewController release];
}

#pragma mark -
#pragma mark Configuring table view cells

#define NAME_TAG 1
#define TIME_TAG 2
#define IMAGE_TAG 3


#define LEFT_COLUMN_OFFSET 10.0
#define LEFT_COLUMN_WIDTH 100

#define MIDDLE_COLUMN_OFFSET 120
#define MIDDLE_COLUMN_WIDTH 120

#define RIGHT_COLUMN_OFFSET 220.0

#define MAIN_FONT_SIZE 18.0
#define LABEL_HEIGHT 26.0

#define IMAGE_SIDE 30

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	CGFloat result = 64.0f;
	
	return result;
}

//- (UITableViewCell *)tableViewCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
//	
//	/*
//	 Create an instance of UITableViewCell and add tagged subviews for the name, local time, and quarter image of the time zone.
//	 */
//	
//	UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
//	
//	/*
//	 Create labels for the text fields; set the highlight color so that when the cell is selected it changes appropriately.
//	 */
//	UILabel *label;
//	CGRect rect;
//	
//	User *cellValue;
//	
//	
//	cellValue = [viewData objectAtIndex:indexPath.row];	
//	
//	rect = CGRectMake( LEFT_COLUMN_OFFSET, (ROW_HEIGHT - IMAGE_SIDE) / 2.0, 120, LABEL_HEIGHT);
//	label = [[UILabel alloc] initWithFrame:rect];
//	label.tag = NAME_TAG;
//	label.font = [UIFont boldSystemFontOfSize:MAIN_FONT_SIZE];
//	label.adjustsFontSizeToFitWidth = YES;
//	
//	label.highlightedTextColor = [UIColor whiteColor];
//	int qnum =  cellValue.num;
//	NSString *qstr = [NSString stringWithFormat:@"%@ %d", @"Question", qnum];
//	label.text = qstr;
//	[cell.contentView addSubview:label];
//	[label release];
//	
//	// Create a label for the time.
//	/*
//	 rect = CGRectMake(MIDDLE_COLUMN_OFFSET, (ROW_HEIGHT - LABEL_HEIGHT) / 2.0, MIDDLE_COLUMN_WIDTH, LABEL_HEIGHT);
//	 label = [[UILabel alloc] initWithFrame:rect];
//	 label.tag = TIME_TAG;
//	 label.font = [UIFont systemFontOfSize:MAIN_FONT_SIZE];
//	 label.textAlignment = UITextAlignmentRight;
//	 [cell.contentView addSubview:label];
//	 label.highlightedTextColor = [UIColor whiteColor];
//	 [label release];
//	 */
//	
//	// Create an image view for the quarter image.
//	rect = CGRectMake(RIGHT_COLUMN_OFFSET, (ROW_HEIGHT - IMAGE_SIDE) / 2.0, IMAGE_SIDE, IMAGE_SIDE);
//	if(cellValue.image != nil){
//		UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
//		imageView.tag = IMAGE_TAG;
//		imageView.image = cellValue.image;
//		[cell.contentView addSubview:imageView];
//		[imageView release];	
//	}else {
//		label = [[UILabel alloc] initWithFrame:rect];
//		label.tag = IMAGE_TAG;
//		label.font = [UIFont boldSystemFontOfSize:MAIN_FONT_SIZE];
//		label.adjustsFontSizeToFitWidth = YES;
//		label.highlightedTextColor = [UIColor whiteColor];
//		label.text = cellValue.choice;
//		[cell.contentView addSubview:label];
//		[label release];
//		
//	}	
//	
//	return cell;
//}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


- (void) viewWillAppear:(BOOL)animated{
	NSLog(@"question view will appear");
	[myscrollView reloadData];
	[self.view setNeedsDisplay];
}


- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
